package smcms.service.resources.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import smcms.commons.api.entity.result.CommonsResult;
import smcms.service.resources.FeignService.StoreFeignService;
import smcms.service.resources.Service.PermissionService;
import smcms.service.resources.Service.ResourcesService;
import smcms.service.resources.entity.Permission;
import smcms.service.resources.entity.Permissions;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ResourcesController")
public class ResourcesController {
    @Autowired
    private CommonsResult commonsResult;
    @Autowired
    private ResourcesService resourcesService;
    @PostMapping("/getCurrentPermission")
    public CommonsResult getCurrentPermission() throws ClassNotFoundException {
        List<Permissions> permissions = resourcesService.getCurrentPermission();
        return commonsResult.success(permissions);
    }
    @GetMapping("/syncPermission")
    public CommonsResult syncPermission(){
        CommonsResult commonsResult = resourcesService.syncPermission();
        return commonsResult;
    }
    @PostMapping("/getOwnPermission")
    public CommonsResult getOwnPermission(@RequestBody Map<String,String> username){
        List<Permissions> permissions = resourcesService.getOwnPermission(username.get("username"));
        return commonsResult.success(permissions);
    }
    @PostMapping("/grantePermission")
    public CommonsResult grantePermission(@RequestBody Permission permission){
        CommonsResult commonsResult = resourcesService.grantePermission(permission);
        return commonsResult;
    }
}
